package com.lz.manage.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lz.common.annotation.Log;
import com.lz.common.core.controller.BaseController;
import com.lz.common.core.domain.AjaxResult;
import com.lz.common.enums.BusinessType;
import com.lz.manage.model.domain.FolderInfo;
import com.lz.manage.model.vo.folderInfo.FolderInfoVo;
import com.lz.manage.model.dto.folderInfo.FolderInfoQuery;
import com.lz.manage.model.dto.folderInfo.FolderInfoInsert;
import com.lz.manage.model.dto.folderInfo.FolderInfoEdit;
import com.lz.manage.service.IFolderInfoService;
import com.lz.common.utils.poi.ExcelUtil;

/**
 * 文件夹信息Controller
 *
 * @author YY
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/manage/folderInfo")
public class FolderInfoController extends BaseController
{
    @Resource
    private IFolderInfoService folderInfoService;

    /**
     * 查询文件夹信息列表
     */
    @PreAuthorize("@ss.hasAnyPermi('manage:folderInfo:list,manage:folderInfo:query')")
    @GetMapping("/list")
    public AjaxResult list(FolderInfoQuery folderInfoQuery)
    {
        FolderInfo folderInfo = FolderInfoQuery.queryToObj(folderInfoQuery);
        List<FolderInfo> list = folderInfoService.selectFolderInfoList(folderInfo);
        List<FolderInfoVo> listVo= list.stream().map(FolderInfoVo::objToVo).collect(Collectors.toList());
        return success(listVo);
    }

    /**
     * 导出文件夹信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:folderInfo:export')")
    @Log(title = "文件夹信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FolderInfoQuery folderInfoQuery)
    {
        FolderInfo folderInfo = FolderInfoQuery.queryToObj(folderInfoQuery);
        List<FolderInfo> list = folderInfoService.selectFolderInfoList(folderInfo);
        ExcelUtil<FolderInfo> util = new ExcelUtil<FolderInfo>(FolderInfo.class);
        util.exportExcel(response, list, "文件夹信息数据");
    }

    /**
     * 获取文件夹信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:folderInfo:query')")
    @GetMapping(value = "/{folderId}")
    public AjaxResult getInfo(@PathVariable("folderId") Long folderId)
    {
        FolderInfo folderInfo = folderInfoService.selectFolderInfoByFolderId(folderId);
        return success(FolderInfoVo.objToVo(folderInfo));
    }

    /**
     * 新增文件夹信息
     */
    @PreAuthorize("@ss.hasPermi('manage:folderInfo:add')")
    @Log(title = "文件夹信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FolderInfoInsert folderInfoInsert)
    {
        FolderInfo folderInfo = FolderInfoInsert.insertToObj(folderInfoInsert);
        return toAjax(folderInfoService.insertFolderInfo(folderInfo));
    }

    /**
     * 修改文件夹信息
     */
    @PreAuthorize("@ss.hasPermi('manage:folderInfo:edit')")
    @Log(title = "文件夹信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FolderInfoEdit folderInfoEdit)
    {
        FolderInfo folderInfo = FolderInfoEdit.editToObj(folderInfoEdit);
        return toAjax(folderInfoService.updateFolderInfo(folderInfo));
    }

    /**
     * 删除文件夹信息
     */
    @PreAuthorize("@ss.hasPermi('manage:folderInfo:remove')")
    @Log(title = "文件夹信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{folderIds}")
    public AjaxResult remove(@PathVariable Long[] folderIds)
    {
        return toAjax(folderInfoService.deleteFolderInfoByFolderIds(folderIds));
    }
}
